<?php

namespace App\Constants;

use App\Constants\AbstractEnum;

/**
 * 存储类型枚举
 * 定义文件存储的各种方式和位置
 */
class StorageTypeEnum extends AbstractEnum
{
    // 本地存储
    public const LOCAL = 'local';           // 本地文件系统
    public const NFS = 'nfs';              // NFS网络文件系统
    public const CEPH = 'ceph';            // Ceph分布式存储

    // 云存储
    public const AWS_S3 = 'aws_s3';        // Amazon S3
    public const ALICLOUD_OSS = 'alicloud_oss'; // 阿里云OSS
    public const TENCENT_COS = 'tencent_cos'; // 腾讯云COS
    public const QINIU_KODO = 'qiniu_kodo'; // 七牛云Kodo
    public const BAIDU_BOS = 'baidu_bos';   // 百度云BOS

    // CDN
    public const CDN = 'cdn';              // CDN加速
    public const CLOUDFLARE_R2 = 'cloudflare_r2'; // Cloudflare R2

    /**
     * 获取存储类型标签
     */
    public static function getLabels(): array
    {
        return [
            self::LOCAL => '本地存储',
            self::NFS => 'NFS网络存储',
            self::CEPH => 'Ceph分布式存储',
            self::AWS_S3 => 'Amazon S3',
            self::ALICLOUD_OSS => '阿里云OSS',
            self::TENCENT_COS => '腾讯云COS',
            self::QINIU_KODO => '七牛云Kodo',
            self::BAIDU_BOS => '百度云BOS',
            self::CDN => 'CDN加速',
            self::CLOUDFLARE_R2 => 'Cloudflare R2',
        ];
    }

    /**
     * 获取存储类型描述
     */
    public static function getDescriptions(): array
    {
        return [
            self::LOCAL => '本地服务器文件系统存储，适用于小型应用',
            self::NFS => '网络文件系统存储，支持多服务器共享',
            self::CEPH => '分布式对象存储系统，适合大规模存储',
            self::AWS_S3 => '亚马逊简单存储服务，全局CDN加速',
            self::ALICLOUD_OSS => '阿里云对象存储服务，国内CDN加速',
            self::TENCENT_COS => '腾讯云对象存储服务，国内CDN加速',
            self::QINIU_KODO => '七牛云对象存储服务，全球CDN加速',
            self::BAIDU_BOS => '百度云对象存储服务，国内CDN加速',
            self::CDN => '内容分发网络，加速文件访问',
            self::CLOUDFLARE_R2 => 'Cloudflare R2存储，性价比高',
        ];
    }

    /**
     * 获取存储类型图标
     */
    public static function getIcons(): array
    {
        return [
            self::LOCAL => 'server',
            self::NFS => 'network-wired',
            self::CEPH => 'database',
            self::AWS_S3 => 'aws',
            self::ALICLOUD_OSS => 'cloud',
            self::TENCENT_COS => 'cloud',
            self::QINIU_KODO => 'cloud-upload-alt',
            self::BAIDU_BOS => 'cloud',
            self::CDN => 'globe',
            self::CLOUDFLARE_R2 => 'cloud',
        ];
    }

    /**
     * 获取存储类型的费用等级
     */
    public static function getCostLevels(): array
    {
        return [
            self::LOCAL => 'free',         // 免费
            self::NFS => 'low',           // 低成本
            self::CEPH => 'medium',       // 中等成本
            self::CLOUDFLARE_R2 => 'low',  // 低成本
            self::QINIU_KODO => 'medium', // 中等成本
            self::BAIDU_BOS => 'medium',  // 中等成本
            self::ALICLOUD_OSS => 'medium', // 中等成本
            self::TENCENT_COS => 'medium', // 中等成本
            self::AWS_S3 => 'high',       // 高成本
            self::CDN => 'high',          // 高成本
        ];
    }

    /**
     * 获取存储类型的速度等级
     */
    public static function getSpeedLevels(): array
    {
        return [
            self::LOCAL => 'fastest',     // 最快
            self::NFS => 'fast',         // 快
            self::CEPH => 'medium',      // 中等
            self::CLOUDFLARE_R2 => 'medium', // 中等
            self::QINIU_KODO => 'fast',   // 快
            self::BAIDU_BOS => 'fast',   // 快
            self::ALICLOUD_OSS => 'fast', // 快
            self::TENCENT_COS => 'fast', // 快
            self::AWS_S3 => 'medium',    // 中等
            self::CDN => 'fastest',      // 最快（CDN加速）
        ];
    }

    /**
     * 获取存储类型的可靠性等级
     */
    public static function getReliabilityLevels(): array
    {
        return [
            self::LOCAL => 'low',         // 低可靠性
            self::NFS => 'medium',       // 中等可靠性
            self::CEPH => 'high',        // 高可靠性
            self::CLOUDFLARE_R2 => 'high', // 高可靠性
            self::QINIU_KODO => 'high',   // 高可靠性
            self::BAIDU_BOS => 'high',   // 高可靠性
            self::ALICLOUD_OSS => 'high', // 高可靠性
            self::TENCENT_COS => 'high', // 高可靠性
            self::AWS_S3 => 'highest',   // 最高可靠性
            self::CDN => 'high',         // 高可靠性
        ];
    }

    /**
     * 检查是否为本地存储
     */
    public static function isLocal(string $type): bool
    {
        return in_array($type, [self::LOCAL, self::NFS, self::CEPH]);
    }

    /**
     * 检查是否为云存储
     */
    public static function isCloud(string $type): bool
    {
        return in_array($type, [
            self::AWS_S3, self::ALICLOUD_OSS, self::TENCENT_COS,
            self::QINIU_KODO, self::BAIDU_BOS, self::CLOUDFLARE_R2
        ]);
    }

    /**
     * 检查是否为CDN存储
     */
    public static function isCDN(string $type): bool
    {
        return $type === self::CDN;
    }

    /**
     * 获取推荐的存储类型
     */
    public static function getRecommendedTypes(): array
    {
        return [
            'development' => self::LOCAL,
            'staging' => self::LOCAL,
            'production_small' => self::QINIU_KODO,
            'production_medium' => self::ALICLOUD_OSS,
            'production_large' => self::AWS_S3,
        ];
    }

    /**
     * 获取存储类型的配置要求
     */
    public static function getConfigRequirements(string $type): array
    {
        $requirements = [
            self::LOCAL => [],
            self::NFS => ['host', 'path'],
            self::CEPH => ['cluster', 'pool', 'user', 'key'],
            self::AWS_S3 => ['key', 'secret', 'region', 'bucket'],
            self::ALICLOUD_OSS => ['access_key', 'access_secret', 'endpoint', 'bucket'],
            self::TENCENT_COS => ['secret_id', 'secret_key', 'region', 'bucket'],
            self::QINIU_KODO => ['access_key', 'secret_key', 'bucket', 'domain'],
            self::BAIDU_BOS => ['access_key', 'secret_key', 'endpoint', 'bucket'],
            self::CDN => ['url', 'key'],
            self::CLOUDFLARE_R2 => ['account_id', 'access_key', 'secret_key', 'bucket'],
        ];

        return $requirements[$type] ?? [];
    }

    /**
     * 获取存储类型的最大文件大小限制
     */
    public static function getMaxFileSize(string $type): int
    {
        $sizeLimits = [
            self::LOCAL => 10 * 1024 * 1024 * 1024, // 10GB
            self::NFS => 10 * 1024 * 1024 * 1024,   // 10GB
            self::CEPH => 100 * 1024 * 1024 * 1024, // 100GB
            self::AWS_S3 => 5 * 1024 * 1024 * 1024, // 5GB
            self::ALICLOUD_OSS => 5 * 1024 * 1024 * 1024, // 5GB
            self::TENCENT_COS => 5 * 1024 * 1024 * 1024, // 5GB
            self::QINIU_KODO => 1 * 1024 * 1024 * 1024, // 1GB
            self::BAIDU_BOS => 5 * 1024 * 1024 * 1024, // 5GB
            self::CDN => 100 * 1024 * 1024, // 100MB
            self::CLOUDFLARE_R2 => 10 * 1024 * 1024 * 1024, // 10GB
        ];

        return $sizeLimits[$type] ?? 100 * 1024 * 1024; // 默认100MB
    }

    /**
     * 获取支持的文件类型
     */
    public static function getSupportedFileTypes(string $type): array
    {
        // 大部分存储都支持所有文件类型，这里可以根据具体需求定制
        return ['*']; // 支持所有文件类型
    }

    /**
     * 获取存储类型的健康检查方法
     */
    public static function getHealthCheckMethod(string $type): string
    {
        $methods = [
            self::LOCAL => 'filesystem',
            self::NFS => 'filesystem',
            self::CEPH => 'api',
            self::AWS_S3 => 'api',
            self::ALICLOUD_OSS => 'api',
            self::TENCENT_COS => 'api',
            self::QINIU_KODO => 'api',
            self::BAIDU_BOS => 'api',
            self::CDN => 'http',
            self::CLOUDFLARE_R2 => 'api',
        ];

        return $methods[$type] ?? 'unknown';
    }
}
